package com.xingfly.school.student.ohs.remote.controller;

import com.xingfly.school.student.acl.pl.request.RegistrationCourseRequest;
import com.xingfly.school.student.ohs.local.appservices.StudentAppService;
import com.xingfly.school.student.ohs.local.pl.response.StudentCourseInfoResponse;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 学生相关API
 * Created by SuperS on 2020/3/27.
 *
 * @author SuperS
 */
@RestController
@RequestMapping("/students")
public class StudentController {

    @Resource
    private StudentAppService studentAppService;


    /**
     * 查询某学生注册的所有课程
     *
     * @param studentId 学生ID
     * @return 课程信息
     */
    @GetMapping("/{id}/courses")
    public List<StudentCourseInfoResponse> findStudentCourses(@PathVariable("id") Long studentId) {
        return studentAppService.findCoursesByStudentId(studentId);
    }

    /**
     * 注册课程API
     *
     * @param courseId 课程ID
     * @param request  注册请求
     * @return result
     */
    @PostMapping("/{id}/registrations")
    public Boolean registration(@PathVariable("id") Long studentId, @RequestBody RegistrationCourseRequest request) {
        return studentAppService.registration(studentId, request);
    }
}
